package com.qf.service.Impl;

import com.qf.mapper.UserMapper;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.UUID;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public User findByUsername(String username) {
        User user=new User();
        user.setUsername(username);
        User param = userMapper.selectOne(user);
        return param;
    }

    @Override
    public Integer saveMessage(User user) {
        String salt= UUID.randomUUID().toString();
//        System.out.println("salt="+salt);
        user.setSalt(salt);
       String newPassword=new Md5Hash(user.getPassword(),salt,1024).toString();
//        System.out.println("newPassword="+newPassword);
        user.setPassword(newPassword);
        return userMapper.insertSelective(user);
    }


}
